*** Stata 15 reproduction code for

*Mader, Matthias & Harald Schoen.
*What a difference an event can make: The European refugee crisis, party competition, and voters’ responses in Germany
*West European Politics


*** Figure A4-3: Party identification after the crisis among prior CDU identifiers
*************************************************************************************

use "DATA_wide.dta", clear

*** Figure A4-3, left panel

	*Change in absolute distance to CDU as IV

	matrix w6w11 = J(5,3,.) // 3 rows, 3 columns 
	matrix w6w13 = J(4,3,.) // 3 rows, 3 columns 
	matrix w6w16 = J(5,3,.) // 3 rows, 3 columns 

	mlogit pi_b11 rdiff6_adist_cdu11 rdiff6_adist_csu11 rdiff6_wadist_cdu11 rdiff6_wadist_csu11 if pi_b7 == 2 // pi_b7 not not measured
	estimate store m_pi_b11
	margins, dydx(rdiff6_adist_cdu11)
	mat r=r(table)
	matrix w6w11[1, 1] = r[1,1]
	matrix w6w11[1, 2] = r[5,1]
	matrix w6w11[1, 3] = r[6,1]
	matrix w6w11[2, 1] = r[1,2]
	matrix w6w11[2, 2] = r[5,2]
	matrix w6w11[2, 3] = r[6,2]
	matrix w6w11[3, 1] = r[1,3]
	matrix w6w11[3, 2] = r[5,3]
	matrix w6w11[3, 3] = r[6,3]
	matrix w6w11[4, 1] = r[1,8]
	matrix w6w11[4, 2] = r[5,8]
	matrix w6w11[4, 3] = r[6,8]

	matrix w6w11[5, 1] = r[1,10]
	matrix w6w11[5, 2] = r[5,10]
	matrix w6w11[5, 3] = r[6,10]
	
	mlogit pi_b13 rdiff6_adist_cdu13 rdiff6_adist_csu13 rdiff6_wadist_cdu13 rdiff6_wadist_csu13 if pi_b7 == 2
	margins, dydx(rdiff6_adist_cdu13)
	mat r=r(table)
	matrix list r
	matrix w6w13[1, 1] = r[1,1]
	matrix w6w13[1, 2] = r[5,1]
	matrix w6w13[1, 3] = r[6,1]
	matrix w6w13[2, 1] = r[1,2]
	matrix w6w13[2, 2] = r[5,2]
	matrix w6w13[2, 3] = r[6,2]
	matrix w6w13[3, 1] = r[1,3]
	matrix w6w13[3, 2] = r[5,3]
	matrix w6w13[3, 3] = r[6,3]
	matrix w6w13[4, 1] = r[1,8]
	matrix w6w13[4, 2] = r[5,8]
	matrix w6w13[4, 3] = r[6,8]
	
	mlogit pi_b16 rdiff6_adist_cdu16 rdiff6_adist_csu16 rdiff6_wadist_cdu16 rdiff6_wadist_csu16 if pi_b7 == 2
	estimate store m_pi_b16
	margins, dydx(rdiff6_adist_cdu16)
	mat r=r(table)
	matrix list r
	matrix w6w16[1, 1] = r[1,1]
	matrix w6w16[1, 2] = r[5,1]
	matrix w6w16[1, 3] = r[6,1]
	matrix w6w16[2, 1] = r[1,2]
	matrix w6w16[2, 2] = r[5,2]
	matrix w6w16[2, 3] = r[6,2]
	matrix w6w16[3, 1] = r[1,3]
	matrix w6w16[3, 2] = r[5,3]
	matrix w6w16[3, 3] = r[6,3]
	matrix w6w16[4, 1] = r[1,8]
	matrix w6w16[4, 2] = r[5,8]
	matrix w6w16[4, 3] = r[6,8]

	matrix w6w16[5, 1] = r[1,10]
	matrix w6w16[5, 2] = r[5,10]
	matrix w6w16[5, 3] = r[6,10]

*** Create Figure A4-3, left panel
	coefplot (matrix(w6w11[,1]), ci((w6w11[,2] w6w11[,3])) msymbol(circle) mcolor(edkblue) msize(large) ciopts(recast(rbar) barwidth(0.03) color(edkblue)) offset(0.1)) ///
			 (matrix(w6w13[,1]), ci((w6w13[,2] w6w13[,3])) msymbol(circle) mcolor(edkblue*.7) msize(large) ciopts(recast(rbar) barwidth(0.03) color(edkblue*.7)) offset(0)) ///
			 (matrix(w6w16[,1]), ci((w6w16[,2] w6w16[,3])) msymbol(circle) mcolor(edkblue*.4) msize(large) ciopts(recast(rbar) barwidth(0.03) color(edkblue*.4)) offset(-0.1)) ///
			,scheme(plottigblind) /// 
			coeflabels(r1="PI CDU/CSU" r2="PI CDU" r3="PI CSU" r4="PI AfD" r5="No Party", labsize(large) labcolor(gs0)) ///
			xscale(range(-.65 .6)) xlabel(-.6 (.2) .6, noticks labsize(large) labcolor(gs0)) xmtick(none) ///
			legend(order(1 "w7" 3 "w8" 5 "w9" ) position(6) col(4)  size(large) symxsize(5) region(lcolor(gs16)))  /// 
			plotregion(color(gs15)) ///
			graphregion(margin(-5 0 -5 0)) ysize(2.5) xsize(3.5)  /// scale(.8)
			title("Effects of {&Delta} in absolute distance to CDU on...", size(large) color(gs0)) ///
			name(FigA4_3a, replace)



*** Figure A4-3, left panel
	*Immigration attitude as IV
	
	*Reminder: The differentiation in party identification is only possible with data from the 2017 Campaign Panel (not with the Intermediate Inquiry 2016)

	matrix w7w10x = J(5,3,.) // 3 rows, 3 columns 
	matrix w7w17x = J(5,3,.) // 3 rows, 3 columns 


	mlogit pi_b10 immi7 c.diff7_immi10 welfare7 c.diff7_welfare10 if pi_b7 == 2, baseoutcome(1)
	estimate store m_pi_b10
	margins, dydx(immi7)
	mat r=r(table)
	matrix w7w10x[1, 1] = r[1,1]
	matrix w7w10x[1, 2] = r[5,1]
	matrix w7w10x[1, 3] = r[6,1]
	matrix w7w10x[2, 1] = r[1,2]
	matrix w7w10x[2, 2] = r[5,2]
	matrix w7w10x[2, 3] = r[6,2]
	matrix w7w10x[3, 1] = r[1,3]
	matrix w7w10x[3, 2] = r[5,3]
	matrix w7w10x[3, 3] = r[6,3]
	matrix w7w10x[4, 1] = r[1,8]
	matrix w7w10x[4, 2] = r[5,8]
	matrix w7w10x[4, 3] = r[6,8]

	matrix w7w10x[5, 1] = r[1,10]
	matrix w7w10x[5, 2] = r[5,10]
	matrix w7w10x[5, 3] = r[6,10]
	
	mlogit pi_b17 immi7 c.diff7_immi17 welfare7 c.diff7_welfare17 if pi_b7 == 2, baseoutcome(1)
	estimate store m_pi_b17
	margins, dydx(immi7)
	mat r=r(table)
	matrix list r
	matrix w7w17x[1, 1] = r[1,1]
	matrix w7w17x[1, 2] = r[5,1]
	matrix w7w17x[1, 3] = r[6,1]
	matrix w7w17x[2, 1] = r[1,2]
	matrix w7w17x[2, 2] = r[5,2]
	matrix w7w17x[2, 3] = r[6,2]
	matrix w7w17x[3, 1] = r[1,3]
	matrix w7w17x[3, 2] = r[5,3]
	matrix w7w17x[3, 3] = r[6,3]
	matrix w7w17x[4, 1] = r[1,8]
	matrix w7w17x[4, 2] = r[5,8]
	matrix w7w17x[4, 3] = r[6,8]

	matrix w7w17x[5, 1] = r[1,10]
	matrix w7w17x[5, 2] = r[5,10]
	matrix w7w17x[5, 3] = r[6,10]

*** Create Figure A4-3, right panel
	coefplot (matrix(w7w10x[,1]), ci((w7w10x[,2] w7w10x[,3])) msymbol(circle) mcolor(edkblue*.7) msize(large) ciopts(recast(rbar) barwidth(0.03) color(edkblue*.7)) offset(.05)) ///
			 (matrix(w7w17x[,1]), ci((w7w17x[,2] w7w17x[,3])) msymbol(circle) mcolor(edkblue*.4) msize(large) ciopts(recast(rbar) barwidth(0.03) color(edkblue*.4)) offset(-0.05)) ///
			,scheme(plottigblind) /// 
			coeflabels(r1="PI CDU/CSU" r2="PI CDU" r3="PI CSU" r4="PI AfD" r5="No Party", labsize(large) labcolor(gs0)) ///
			xscale(range(-.65 .6)) xlabel(-.6 (.2) .6, noticks labsize(large) labcolor(gs0)) xmtick(none) ///
			legend(order(1 "w6" 3 "w10" ) position(6) col(4)  size(large) symxsize(5) region(lcolor(gs16)))  /// 
			plotregion(color(gs15)) ///
			graphregion(margin(-5 0 -5 0)) ysize(2.5) xsize(3.5)  /// scale(.8)
			title("Effects of prior immigration attitude on...", size(large) color(gs0)) ///
			name(FigA4_3b, replace)
